﻿using Sustainalytics.ClientDW.Synchronization.SyncESGData.AbstractClassesAndInterfaces;
using Sustainalytics.SharedEntities.EsgResearch;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Sustainalytics.ClientDW.Synchronization.SyncESGData.ESGAssessmentThresholdLogic
{
    public class EsgAssessmentThresholdOrchestrator : IComprehensiveEsgSyncOrchestrator<EsgAssessmentThreshold>
    {
        private readonly IComprehensiveEsgAssessmentThresholdQuery esgAssessmentThresholdQuery;
        private readonly EsgAssessmentThresholdMapper esgAssessmentThresholdMapper;
        private readonly EsgAssessmentThresholdCommand esgAssessmentThresholdCommand;

        public EsgAssessmentThresholdOrchestrator(EsgAssessmentThresholdQuery esgAssessmentThresholdQuery,
                                                    EsgAssessmentThresholdMapper esgAssessmentThresholdMapper, 
                                                    EsgAssessmentThresholdCommand esgAssessmentThresholdCommand)
        {
            this.esgAssessmentThresholdQuery = esgAssessmentThresholdQuery;
            this.esgAssessmentThresholdMapper = esgAssessmentThresholdMapper;
            this.esgAssessmentThresholdCommand = esgAssessmentThresholdCommand;
        }

        async Task IComprehensiveEsgSyncOrchestrator<EsgAssessmentThreshold>.OrchestrateAsync(IList<EsgAssessmentThreshold> entities, IList<Guid> invalidatedCompaniesIds)
        {
            await esgAssessmentThresholdCommand.ExecuteAsync(esgAssessmentThresholdMapper.MapManyToMany(entities ?? esgAssessmentThresholdQuery.Get()));
        }
    }
}
